package com.jz.netthings.application.providerCreate.controller;


import com.baomidou.mybatisplus.plugins.Page;
import com.jz.netthings.appengine.baseData.ProviderInfo;
import com.jz.netthings.application.providerCreate.bean.QueryProviderInfo;
import com.jz.netthings.application.providerCreate.service.ProviderInfoService;
import com.jz.netthings.application.providerReg.bean.ProviderReg;
import com.jz.netthings.application.providerReg.bean.QueryProviderReg;
import com.jz.netthings.application.providerReg.service.ProviderRegService;
import com.jz.netthings.exception.AdscmSystemException;
import com.jz.netthings.security.utils.Token;
import com.jz.netthings.support.SimpleCoreResponse;
import com.jz.netthings.utils.AdscmBaseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zyl
 * @since 2019-02-28
 */
@RestController
@RequestMapping("/adscm/application/providerInfo")
public class ProviderInfoController {
    @Autowired
    RedisTemplate<Object, Token> tokenRedisTemplate;
    @Autowired
    ProviderInfoService providerInfoService;
    @RequestMapping("/selectProviderInfo")
    public SimpleCoreResponse selectProviderInfo(@RequestBody QueryProviderInfo queryProviderInfo, HttpServletRequest request) throws AdscmSystemException, IOException {
        Page<ProviderInfo> page =new Page<>(queryProviderInfo.getCurrentPage(),queryProviderInfo.getPageSize());
        Page<ProviderInfo>  providerInfos = providerInfoService.selectProviderInfo(page ,queryProviderInfo);
        return new SimpleCoreResponse("200","查询成功" ,providerInfos);
    }
    @RequestMapping("/updateProviderInfo")
    public SimpleCoreResponse updateProviderInfo(@RequestBody ProviderInfo providerInfo, HttpServletRequest request) throws AdscmSystemException, IOException {
        String tokenId = request.getParameter("tokenId");
        Token token = AdscmBaseUtils.getInstance().getTokenByTokenId(tokenId, tokenRedisTemplate);
        Boolean result= providerInfoService.updateProviderInfo(providerInfo ,token);
        return new SimpleCoreResponse("200","查询成功" ,result);
    }
    @RequestMapping("/insertProviderInfo")
    public SimpleCoreResponse insertProviderInfo(@RequestBody ProviderInfo providerInfo, HttpServletRequest request) throws AdscmSystemException, IOException {
        String tokenId = request.getParameter("tokenId");
        Token token = AdscmBaseUtils.getInstance().getTokenByTokenId(tokenId, tokenRedisTemplate);
        Boolean result= providerInfoService.insertProviderInfo(providerInfo ,token);
        return new SimpleCoreResponse("200","查询成功" ,result);
    }


}

